Release 10.1A: OpenEdge Development:
Progress Dynamics Advanced Development
Using custom super procedures in Progress Dynamics
This section, which explains how to create super procedures in Progress Dynamics and attach them to your objects, starts with a review of just what super procedures are and how they work.
Super procedures provide a measure of inheritance and class behavior within the Progress 4GL. Code in a super procedure becomes an extension of the code written in another procedure, so to the extent that a single super procedure can be associated with many other procedures, it can give all of those other procedures the same standard behavior. The super procedure needs to be run only once within a session, where it can support any number of other procedures.
On the face of it, a super procedure looks just like any other Progress procedure. It contains no special code and no special declarations. It is run as a persistent procedure within a session, and can be started by the first procedure that needs it, or by any other mechanism. What makes it a super procedure is a method in the other procedure that wants to inherit its code, the
ADD-SUPER-PROCEDUREmethod on the procedure handle. In this example, a procedure calledbaseproc.pruns the super proceduresuperproc.pand then makes the association:
At this point, the Progress interpreter associates superproc.p and all its internal procedures and functions with baseproc.p. Any
RUNstatement inbaseproccauses the interpreter to search first inbaseproc.pand then insuperproc.pfor the entry point. It executes the first one it finds. In this way the contents of the super procedure transparently act as if part of the base procedure.In addition, because
baseproc.pandsuperproc.pare in fact separately compiled procedures, each has its own namespace for procedure and function names, as well as for variables and other language constructs. This means that the same internal procedure or function name can appear in both procedures. The super procedure can provide standard behavior in the form of an internal procedure or function, and then the base procedure can override that behavior or augment it.To do this, the procedure or function in the base procedure must use the syntax
RUNSUPER(for an internal procedure) orSUPER()(for a function) to invoke the standard behavior.The interpreter locates and executes the occurrence of the procedure or function in the base procedure first, and then counts on the base procedure to invoke the same entry point in the super procedure if it wants to. Any other code can come before or after the
RUNSUPERstatement.A base procedure can add any number of super procedures, just by invoking the
ADD-SUPER-PROCmethod multiple times. The procedures are kept in a kind of last-in-first-out (LIFO) stack, so the last one added is the first one searched for an entry point. When a super procedure is added to a stack, if that procedure also has super procedures, they too are added to the stack. Each one can pass control up the stack with its ownRUNSUPERstatement.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |